<?php
declare (strict_types = 1);

namespace app\middleware;

use app\exception\PremEx;
use app\lib\token\JwtToken;
use app\lib\token\UserToken;

class IsLogin {
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $vars = JwtToken::getValues();
        if ($vars == false) {
            throw new PremEx('未登录或登录超时', PremEx::LoginTimeout);
        }
        // TODO: 保持活跃用户
        return $next($request);
    }
}
